{% extends "content_temp.html" %}
{% block content %}
{% load i18n %}

{% block extrajs %}
<script type="text/javascript">
Ext.onReady(function(){
    var btn = Ext.get("btn_registra");
    btn.on("click", function(){
		btn.dom.disabled = false;
        Ext.Ajax.defaultHeaders = {
            'Accept': 'application/json'
        };
        var resp = Ext.Ajax.request({
            url: '/aib_login/registra/',
            method: 'POST',
            success: function(resp) {
                var item = Ext.decode(resp.responseText);
				
				var i = 0;
				for (key in item){
					//alert(item[key]);
					Ext.get(key+"_erro").dom.innerHTML="<ul class='errorlist' style='color:red;'>"+String(item[key])+"</ul>";
					i++;
				}
				
				
				if (i==0){
					var theForm = Ext.get('registraForm').dom;
					var num_of_elements = theForm.length;
					for (var j=0; j<num_of_elements; j++){
						var theElement = theForm.elements[j];
						var	theElement_erroDiv = Ext.get(theElement.name+"_erro");
						if (theElement_erroDiv!=null){
							Ext.get(theElement.name+"_erro").dom.innerHTML="";
							alert(theElement.name);
						}
						
						//theElement.innerText="";
					}
					
					Ext.Msg.alert('Registro','Seu registro foi completado com sucesso.');
				}
				
				
				//Ext.get('contentDiv').dom.innerHTML=String(item.form);
            },
            failure: function() {
                // Prompt for user data and process the result using a callback:
				Ext.Msg.alert('Erro:', 'Falha de conexao com o servidor.');
            },
			params: function() {
				var parametros = {};
				var theForm = Ext.get('registraForm').dom;
				var num_of_elements = theForm.length;
				//alert(num_of_elements);
				for (var i=0; i<num_of_elements; i++){
					var theElement = theForm.elements[i];
					var element_type = theElement.type;
					var element_name = theElement.name;
					var element_value = theElement.value;
					parametros[element_name]=element_value;
					//alert(parametros[element_name]);
				}
				
				return parametros;
            },
        });
    }, true, {
        single: false
    });
});
</script>
{% endblock %}

<!-- Pagetitle -->
<h1 class="pagetitle">Registro de nova conta:</h1>

    <div class="column1-unit">
<div class="contactform">
<form action="/contact/" method="post" id="registraForm">
<fieldset><legend>&nbsp;CONTACT DETAILS&nbsp;</legend>
    {% for field in form %}
        <div class="fieldWrapper">
            {{ field.errors }}
            <div id="{{ field.html_name }}_erro"></div>
            <p><label class="left" for="{{ field.html_name }}">{{ field.label }}</label>
            <input class="field" class="field" type="text" name="{{ field.html_name }}" id="{{ field.html_name }}" />
            </p>
        </div>
    {% endfor %}
    <p><input class="button" id="btn_registra" type="button" value="Cadastrar" /></p>
</fieldset>    
</form>
  </div>              
</div> 

{% block content-related %}
	<div class="box">
		<h3>{% trans "Passo 1:" %}</h3>
		<p>{% trans "Para se cadastrar é muito fácil, são apenas 3 passos." %}.</p>
	</div>
{% endblock %}

{% endblock content %}
